/*
 *      Created on: March 9, 2011
 *      Author: topcoder
 */
#include <Measure.h>
#include <Unit.h>

bool isSameType(const UnitType firstType, const UnitType secondType)
{
    return ((firstType == secondType) && (firstType != INVALIDTYPE));
}

Measure::Measure(unsigned long amount, const Unit& unit)
{
    quantity_m = amount * unit.getRatio();
    unitType_m = unit.getType();
}

Measure::Measure(unsigned long amount, const UnitType& unitType):quantity_m(amount),unitType_m(unitType)
{
}

bool Measure::operator == (const Measure &measure)const
{
    return (isSameType(unitType_m, measure.unitType_m)&&(quantity_m == measure.quantity_m));
}

Measure Measure::operator + (const Measure& measure)const
{
    return(isSameType(unitType_m, measure.unitType_m)? \
           Measure(quantity_m+measure.quantity_m, unitType_m): NULL);

}

ostream & operator << (ostream & os, Measure & quantity)
{
	return quantity.print();

}

ostream Measure::print()
{
    return Unit::print(quantity_m, unitType_m);
}

